<template>
  <div id="app">
    <div class="control">
      <div class="bar">
        <el-button type="text" style="color: #fff">
          {{ Math.round(scale * 100) }} %
        </el-button>
        <el-slider
          class="slider"
          v-model="scale"
          :step="0.01"
          :min="0.1"
          :max="1.5"
          :format-tooltip="formatTooltip"
        ></el-slider>
      </div>
    </div>
    <!-- 第一层（假想的设备屏幕层），用于限定最大宽度（可以假想为手机的屏幕宽度），
         自身的宽度本示例由 absolute 来设定（当然你也可以用其它方法来设定），
         里面的内容超过自身宽度后，会出现滚动条 -->
    <div class="screen-layer">
      <!-- 第二层：用于设定视口的尺寸和位置（可以不要这层），通常会留几十像素的白边，方便观看和操作，
           可以想象为 word 文档周围的空白边），尺寸是根据初始画布的大小来进行缩放计算的 -->
      <div class="viewport-layer" :style="computeViewport">
        <!-- 第三层：缩放控制层，用于对画布尺寸大小进行缩放 -->
        <div class="scale-layer" :style="computeScale">
          <!-- 第四层：画布，尺寸大小为初始设定的画布大小，比如：1920 * 1080 -->
          <div class="canvas-layer" :style="computeCanvas"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
/**
 * 可视化后台布局 demo
 */
export default {
  name: "Backend",
  data() {
    return {
      scale: 1,
      canvasWidth: 1920,
      canvasHeight: 1080,
    };
  },
  computed: {
    computeScale() {
      return {
        transform: `scale(${this.scale})`,
      };
    },
    computeViewport() {
      return {
        width: Math.round(this.scale * this.canvasWidth + 50) + "px",
        height: Math.round(this.scale * this.canvasHeight + 50) + "px",
      };
    },
    computeCanvas() {
      return {
        width: this.canvasWidth + "px",
        height: this.canvasHeight + "px",
      };
    },
  },
  methods: {
    formatTooltip(val) {
      return Math.round(val * 100) + "%";
    },
  },
};
</script>
<style scoped>
* {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
body {
  margin: 0;
  padding: 0;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}
:-moz-placeholder {
  color: #8f8f8f !important;
  font-weight: normal !important;
}
::-moz-placeholder {
  color: #8f8f8f !important;
  font-weight: normal !important;
}
:-ms-input-placeholder {
  color: #8f8f8f !important;
  font-weight: normal !important;
}
::-webkit-input-placeholder {
  color: #8f8f8f !important;
  font-weight: normal !important;
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-button {
  display: none;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-corner {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: #b8b8b8;
  /* background-clip: content-box; */
}
::-webkit-scrollbar-thumb:hover {
  background: #9f9f9f;
}
.viewport-wrapper::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

:root,
body {
  height: 100%;
}
#app {
  height: 100%;
}
.control {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: rgb(5, 33, 59);
}
.bar {
  width: 400px;
  height: inherit;
  margin: 0 auto;
}
.slider {
  width: 87%;
  float: right;
}
.screen-layer {
  position: absolute;
  top: 60px;
  left: 100px;
  right: 100px;
  bottom: 30px;
  overflow: auto;
  box-shadow: 0 0 4px 2px #ccc;
  background: url(../assets/bg_m.png) center / 8px 8px;
}
.viewport-layer {
  /* position: relative; */
  display: flex;
  justify-content: center;
  align-items: center;
  min-width: 100%;
  min-height: 100%;
}
.scale-layer {
  transition: transform ease 0.15s;
  transform-origin: center center;
  box-shadow: rgba(0, 0, 0, 0.24) 0px 2px 4px 0px;
}
.canvas-layer {
  position: relative;
  background: url(../assets/canvas_bg.jpeg) center / 100% 100% no-repeat;
}
</style>
